package menu

import (
	"news_for_deepseek_interface/controller"
	"news_for_deepseek_interface/dto"
	menuDto "news_for_deepseek_interface/dto/admin/system/menu"
	menuService "news_for_deepseek_interface/service/admin/system/menu"

	"github.com/gin-gonic/gin"
)

func List(c *gin.Context) {
	// 1. 参数绑定
	var params menuDto.ListMenuRequest
	if err := c.ShouldBindJSON(&params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	// 2. 验证参数
	if err := dto.Validate(params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	// 3. 调用服务层处理登录逻辑
	response, err := menuService.ListMenu(params)
	if err != nil {
		controller.Fail(c, controller.BusinessError, err.Error())
		return
	}

	// 4. 返回成功响应
	controller.Success(c, response)
}
